var mysql = require('mysql');
var mysql_config = require("../../util/mysql_config");
var log = require("./../../util/loginfo").getInstand;

var pool = mysql.createPool({
    connectionLimit: 10000,
    host: mysql_config.host,
    user: mysql_config.user,
    password: mysql_config.password,
    port: mysql_config.port,
    database: 'ym_manage'
});

//获取中马号
exports.getHorseNo = function getHorseNo(key, callback) {
    var sql = "select value, `key` from game_fengkong where gameId = 1006 and `key` = ?";
    var values = [];
    values.push(key);

    pool.getConnection(function (err, connection) {
        connection.query({sql: sql, values: values}, function (err, rows) {
            connection.release();
            if (err) {
                log.err("getHorseNo error == " + err);
                callback(0);
            } else {
                if (rows[0]) {
                    callback(1, rows);
                } else {
                    callback(0);
                }
            }
        });
        values = [];
    });
};

exports.clearHorseNo = function clearHorseNo(key, callback) {

    log.info("clearHorseNo begin");
    var sql = "delete from game_fengkong where gameId = 1006 and `key` = ?";
    var values = [];
    values.push(key);

    pool.getConnection(function (err, connection) {
        connection.query({sql: sql, values: values}, function (err, rows) {
            if (err) {
                log.info("clearHorseNo");
                log.err(err);
                callback(0);
            } else {
                callback(1);
            }
        });
        values = [];
        connection.release();
    });
};



